﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Snooze.Model
{
    using Castle.ActiveRecord;

    [ActiveRecord]
    public class Alarm : Persistent, IAlarm
    {
        #region members

        public event EventHandler AlarmExcecuted;

        private bool active = true;
        private int volume = 100;
        private DateTime time = new DateTime();
        private Snooze snooze;
        private Person person;
        
        #endregion

        #region public persistent properties

        [Property(Column = "ALARM_ACTIVE")] // "alarm" is reserved word in db
        public bool Active
        {
            get { return active; }
            set { active = value; }
        }

        [Property]
        public int Volume
        {
            get { return volume; }
            set { volume = value; }
        }

        [Property(Column = "ALARM_TIME")] // "time" is reserved word in db
        public DateTime Time
        {
            get { return time; }
            set { time = value; }
        }

        [BelongsTo]
        public Snooze Snooze
        {
            get { return snooze; }
            set { snooze = value; }
        }

        [BelongsTo]
        public Person Person
        {
            get { return person; }
            set { person = value; }
        }
        #endregion

        #region protected members
        protected void OnExcecuted(EventArgs e)
        {
            if (AlarmExcecuted != null)
                AlarmExcecuted(this, e);

        }
        #endregion

        #region public members
        public void Excecute()
        {
            OnExcecuted(new EventArgs());
        }
        #endregion
    }
}
